package com.walle.concurrenttest.pattern.guardedsuspension;

import com.sun.org.apache.regexp.internal.RE;

import java.util.LinkedList;

/**
 * @author zhangjiapeng
 * @Package com.walle.concurrenttest.pattern.guardedsuspension
 * @Description: ${todo}
 * @date 2019/2/18 15:19
 */
public class RequestQueue {

    private final LinkedList<Request> queue = new LinkedList<>();

    public synchronized Request getRequest(){
        while (queue.size() <= 0){
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        return queue.removeFirst();
    }

    public synchronized void putRequest(Request request){
        queue.addLast(request);
        notifyAll();
    }
}
